<?php
require_once './vendor/autoload.php';

// 消费者

$delay = new \Delay\DelayQueue();

$delayQueueName = 'delay-order-queue';

$callback = function ($msg) {
	$body = json_decode($msg->body);
    echo sprintf("死信队列监听：接收到过期消息，订单ID是：%s，下单时间是：%s", $body->order_id, date('Y-m-d H:i:s', $body->order_time)) . PHP_EOL;

    //判断订单是否已处理过,未处理则取消
    echo sprintf("死信队列监听：订单ID：%s已取消成功，取消时间是：%s", $body->order_id, date('Y-m-d H:i:s')) . PHP_EOL;

    $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
};

/**
 * 消费已经超时的订单信息，进行处理
 */
$delay->consumeMessage($delayQueueName, $callback);